/*
 * @lc app=leetcode.cn id=6 lang=javascript
 *
 * [6] Z 字形变换
 */

// @lc code=start
/**
 * @param {string} s
 * @param {number} numRows
 * @return {string}
 */
var convert = function (s, numRows) {
    if (numRows == 1) return s
    let arr = []
    for (let i = 0; i < numRows; i++) {
        arr.push([])
    }
    let n = parseInt(2 * (numRows - 1))
    for (let i = 0; i < s.length; i++) {
        let row = i % n
        if (row <= (numRows - 1)) {
            arr[row].push(s[i])
        } else {
            arr[n - row].push(s[i])
        }
    }
    let ans = ''
    for (let i = 0; i < arr.length; i++) {
        for (let j = 0; j < arr[i].length; j++) {
            ans = ans + arr[i][j]
        }
    }
    return ans
};
// @lc code=end
// @after-stub-for-debug-begin
module.exports = convert;
// @after-stub-for-debug-end